hvmloader: Allow default response to be specified to xenstore_read().
authorKeir Fraser <keir@xen.org>
Mon, 25 Jul 2011 13:21:13 +0000 (14:21 +0100)
committerKeir Fraser <keir@xen.org>
Mon, 25 Jul 2011 13:21:13 +0000 (14:21 +0100)
Signed-off-by: Keir Fraser <keir@xen.org>
tools/firmware/hvmloader/hvmloader.c
tools/firmware/hvmloader/smbios.c
tools/firmware/hvmloader/util.h
tools/firmware/hvmloader/xenbus.c

index 4613a736f4f79dec7e20a53e677ec097c3b4e8a5..5e7d1283071823d4213a4703a2d8ef1a57194b83 100644 (file)
@@ -368,9 +368,7 @@ static const struct bios_config *detect_bios(void)
     const struct bios_info *b;
     const char *bios;
 
-    bios = xenstore_read("hvmloader/bios");
-    if ( !bios )
-        bios = "rombios";
+    bios = xenstore_read("hvmloader/bios", "rombios");
 
     for ( b = &bios_configs[0]; b->key != NULL; b++ )
         if ( !strcmp(bios, b->key) )
index 5674bf42c05c57b5e4fca684e8746b288442039d..ea79e9e1b0f8783aac769eb8075f13988391f555 100644 (file)
@@ -315,15 +315,11 @@ smbios_type_0_init(void *start, const char *xen_version,
     p->embedded_controller_minor = 0xff;
 
     start += sizeof(struct smbios_type_0);
-    if ( ((s = xenstore_read("bios-strings/bios-vendor")) == NULL)
-         || (*s == '\0') )
-        s = "Xen";
+    s = xenstore_read("bios-strings/bios-vendor", "Xen");
     strcpy((char *)start, s);
     start += strlen(s) + 1;
 
-    if ( ((s = xenstore_read("bios-strings/bios-version")) == NULL)
-         || (*s == '\0') )
-        s = xen_version;
+    s = xenstore_read("bios-strings/bios-version", xen_version);
     strcpy((char *)start, s);
     start += strlen(s) + 1;
 
@@ -362,28 +358,20 @@ smbios_type_1_init(void *start, const char *xen_version,
 
     start += sizeof(struct smbios_type_1);
     
-    if ( ((s = xenstore_read("bios-strings/system-manufacturer")) == NULL)
-         || (*s == '\0') )
-        s = "Xen";
+    s = xenstore_read("bios-strings/system-manufacturer", "Xen");
     strcpy((char *)start, s);
     start += strlen(s) + 1;
 
-    if ( ((s = xenstore_read("bios-strings/system-product-name")) == NULL)
-         || (*s == '\0') )
-        s = "HVM domU";
+    s = xenstore_read("bios-strings/system-product-name", "HVM domU");
     strcpy((char *)start, s);
     start += strlen(s) + 1;
 
-    if ( ((s = xenstore_read("bios-strings/system-version")) == NULL)
-         || (*s == '\0') )
-        s = xen_version;
+    s = xenstore_read("bios-strings/system-version", xen_version);
     strcpy((char *)start, s);
     start += strlen(s) + 1;
 
     uuid_to_string(uuid_str, uuid); 
-    if ( ((s = xenstore_read("bios-strings/system-serial-number")) == NULL)
-         || (*s == '\0') )
-        s = uuid_str;
+    s = xenstore_read("bios-strings/system-serial-number", uuid_str);
     strcpy((char *)start, s);
     start += strlen(s) + 1;
 
@@ -494,7 +482,7 @@ smbios_type_11_init(void *start)
     {
         path[(sizeof path) - 3] = '0' + ((i < 10) ? i : i / 10);
         path[(sizeof path) - 2] = (i < 10) ? '\0' : '0' + (i % 10);
-        if ( ((s = xenstore_read(path)) == NULL) || (*s == '\0') )
+        if ( ((s = xenstore_read(path, NULL)) == NULL) || (*s == '\0') )
             break;
         strcpy((char *)start, s);
         start += strlen(s) + 1;
index bc86043eec9a3a0f97b6a75634e28fd133a80c7b..464cf98f613526ad04b747aa91927e14923e69c8 100644 (file)
@@ -187,8 +187,11 @@ void xenbus_shutdown(void);
 
 /* Read a xenstore key.  Returns a nul-terminated string (even if the XS
  * data wasn't nul-terminated) or NULL.  The returned string is in a
- * static buffer, so only valid until the next xenstore/xenbus operation. */
-char *xenstore_read(char *path);
+ * static buffer, so only valid until the next xenstore/xenbus operation.
+ * If @default_resp is specified, it is returned in preference to a NULL or
+ * empty string received from xenstore.
+ */
+const char *xenstore_read(const char *path, const char *default_resp);
 
 /* Setup PCI bus */
 void pci_setup(void);
index 90245f57b18c4701964bb1c62d763bb79fd8567a..87f03a83f1367b5621f23ffd52d47967658433cb 100644 (file)
@@ -83,7 +83,7 @@ static void ring_wait(void)
 }
 
 /* Helper functions: copy data in and out of the ring */
-static void ring_write(char *data, uint32_t len)
+static void ring_write(const char *data, uint32_t len)
 {
     uint32_t part;
 
@@ -140,8 +140,8 @@ static void ring_read(char *data, uint32_t len)
  * Returns 0 for success, or an errno for error.
  * The answer is returned in a static buffer which is only
  * valid until the next call of xenbus_send(). */
-static int xenbus_send(uint32_t type, uint32_t len, char *data,
-                       uint32_t *reply_len, char **reply_data)
+static int xenbus_send(uint32_t type, uint32_t len, const char *data,
+                       uint32_t *reply_len, const char **reply_data)
 {
     struct xsd_sockmsg hdr;
     evtchn_send_t send;
@@ -190,15 +190,22 @@ static int xenbus_send(uint32_t type, uint32_t len, char *data,
 
 /* Read a xenstore key.  Returns a nul-terminated string (even if the XS
  * data wasn't nul-terminated) or NULL.  The returned string is in a
- * static buffer, so only valid until the next xenstore/xenbus operation. */
-char *xenstore_read(char *path)
+ * static buffer, so only valid until the next xenstore/xenbus operation.
+ * If @default_resp is specified, it is returned in preference to a NULL or
+ * empty string received from xenstore.
+ */
+const char *xenstore_read(const char *path, const char *default_resp)
 {
     uint32_t len = 0;
-    char *answer = NULL;
+    const char *answer = NULL;
 
     /* Include the nul in the request */
     if ( xenbus_send(XS_READ, strlen(path) + 1, path, &len, &answer) )
-        return NULL;
+        answer = NULL;
+
+    if ( (default_resp != NULL) && ((answer == NULL) || (*answer == '\0')) )
+        answer = default_resp;
+
     /* We know xenbus_send() nul-terminates its answer, so just pass it on. */
     return answer;
 }